package com.team12.hotel404.service.serviceImpl;

import com.team12.hotel404.domain.Order;
import com.team12.hotel404.domain.OrderExample;
import com.team12.hotel404.domain.User;
import com.team12.hotel404.mapper.OrderMapper;
import com.team12.hotel404.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;



    /**
     * 列出所有的订单
     * @return
     */
    @Override
    public List<Order> listAllOrder() {
        return orderMapper.selectByExample(new OrderExample());
    }

    /**
     * 根据id查找出特定的订单
     * @param id
     * @return
     */
    @Override
    public Order findOrderById(Integer id) {
        return orderMapper.selectByPrimaryKey(id);
    }

    @Override
    public Order findOrderByUser(User user) {
        // TODO: 2019/7/22
        return null;
    }

    @Override
    public List<Order> findAll() {
        return orderMapper.selectAll();
    }

    @Override
    public List<Order> search(Integer id) {
        List<Order> orders = new ArrayList<>();
        OrderExample orderExample = new OrderExample();
        orderExample.createCriteria().andOrderIdEqualTo(id);
        orders = orderMapper.selectByExample(orderExample);
        return orders;
    }

    @Override
    public List<Order> searchOne(Integer uid) {
        List<Order> orders = new ArrayList<>();
        OrderExample orderExample = new OrderExample();
        orderExample.createCriteria().andUIdEqualTo(uid);
        orders = orderMapper.selectByExample(orderExample);
        return orders;
    }

    @Override
    public List<Order> OrderDetails(Integer id) {
        return orderMapper.OrderDetails(id);
    }

    @Override
    public void insertOrder(Order order1) {
        orderMapper.insert(order1);
    }

    @Override
    public Integer selectLastInsertId() {
        return orderMapper.selectLastInsertId();
    }
}
